<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="/WEB-INF/jsp/include/easyui.jsp" %>
<script src="/plug-in/jquery-easyui-1.5.1/plugins/jquery.choosebox.js"></script>
<%@ include file="/WEB-INF/jsp/include/easyui-layui-upload.jsp" %>
<script type="text/javascript" src="${path}/plug-in/jquery-easyui-1.5.1/plugins/datagrid-cellediting.js"></script>
<%@ include file="../../include/pForm.jsp" %>
<title>出库编辑</title>
<script>
$(function(){
	fn.resetForm();
	var _data = fn.getDialogData();
	var cDialog = null;
	$("#dataGrid").datagrid({
		idField: "id",
		rownumbers: true,
		pagination: true,
		singleSelect: true, 
		url : '/console/com.fs.jzzn.pojo.StorageItem/list',
		queryParams: {
			billNo:_data.billNo,
			billNo_searchType: "eq"
		},
		columns : [[ 
				{field: 'mNo', title: '物料编码', width: 100}
			    , {field: 'mName', title: '物料名称', width: 180} 
		    	,{field: 'mType', title: '物料规格', width: 100}
		    	,{field: 'mUnit', title: '物料单位', width: 80}
		    	,{field: 'mCount', title: '出库数量', width: 80,editor:{type:'numberbox',options:{precision:1}}}
		    	,{field: 'location', title: '库位', width: 75,editor:{type:'text',options:{precision:1}}}
		    	,{field: 'opt', title: '操作', width: 80,formatter: function(value,row,index){
		    		return '<a href="#" onclick="deleteRow('+ index +')">删除</a>';
		    	}}
		]],
		toolbar: [{
			iconCls: 'icon-add', text: '添加', handler: function(){
				cDialog = $("<div/>").dialog("openWin", {
	     		    title: '出库物料选择',   
	     		   	width:  550,
	     		    height: 350,   
	     		    href : '/console/materiel_choose/choosebox',
	     		    buttons : [
	     		        {
			            	   text : "确定", iconCls : "icon-ok", handler : function() {
			            		   var rows = cDialog.iframeWindow.choose() || [];
			            		   $.each(rows, function (i,item) {
			            			   item.mCount = 1;
			            			   $('#dataGrid').datagrid('appendRow',item);
			            		   });
			            		   cDialog.dialog('close');
			            	   }
	     		        },
							{
								text : "关闭", iconCls : "icon-no", handler : function() {
									cDialog.dialog('close');
								}
							}
	     		    ]
	     		});
				cDialog.dialog("center");
			}
		},'-'
		,{
			iconCls: 'icon-help',text: '帮助', handler: function(){
				$.messager.show({ title:'温馨提示', msg: '点击添加按钮，选择出库库物料明细!',timeout:3000, showType:'slide' });
			}
		}]
	}).datagrid('enableCellEditing');
	
	/*表单提交前动作*/
	fn.onBeforeSubmitForm = function(){
		var rows = $("#dataGrid").datagrid('getRows') ;
		for(var index=0,len=rows.length;index<len;index++){
			$("#dataGrid").datagrid('endEdit',index);
		}
		$("input[name=theLibraryItemJson]").val(JSON.stringify(rows));
		return true;
	}
});

function deleteRow(index){
	$("#dataGrid").datagrid('deleteRow',index) ;
}

/*单项工程选择时同时关联选择项目部*/
function selectDepartmant (rows){
	if(rows&& rows.length>=1){
		var record = rows[0];
		$('#department').combobox('setValue', record.department || '');
	}
}
</script>
</head>
<body class="easyui-layout">
	<div class="easyui-panel" data-options="fit:true,border:false" style="padding:10px;">
		<form id="easyuiForm" method="post" action="/console/theLibrary/rewrite/modify" style="width: 850px;">
		 <input type="hidden" name="className" value="com.fs.jzzn.pojo.TheLibrary" />
		 <input type="hidden" name="id" value="" />
		  <input type="hidden" name="status" value="0" />
		 <input type="hidden" name="createrId" value="${SESSION_USER.user.id}" />
		<input type="hidden" name="theLibraryItemJson" value="[]" />
			<div style="margin-bottom:20px">
			  	<input  class="easyui-textbox"  name="billNo" readonly="readonly" style="width:270px;" data-options="label:'出库编号:',required:true,prefix:'CK',timestamp:'yyMMddHHmmss' "/>
			  	<input class="easyui-choosebox easyui-validatebox" name="roadNo" style="width:540px;"   data-options="label:'订单编号:',boxWidth:900,boxHeight:400,boxTitle:'请选择订单编号',textField:'contractNo',valueField:'contractNo',modleName:'order',required:true,callback:selectDepartmant"/>
			 </div>
			 
			 <div style="margin-bottom:20px">
			   	<select class="easyui-combobox" name="pm" style="width:270px;" data-options="label:'项目经理:'" 
					url="/console/user/combobox?duty=项目经理&duty_searchType=eq&textField=nickName&valueField=nickName" >
			   	 </select>
			   	 <select class="easyui-combobox" name="warehouseName" style="width:270px;" data-options="label:'仓库名称:'" 
					url="/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=C3&pCode_searchType=eq&text=东湖落雁岛" >
			 		</select>
			 		<select class="easyui-combobox" id="department" name="department" style="width:270px;" data-options="label:'关联项目部:',loadFilter:fn.departmentFilter" 
						url="/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=A5&pCode_searchType=eq" >
				    </select>
			 </div>
			 
			 <div style="margin-bottom:20px">
			 	 <input class="easyui-textbox" name="picking"  style="width:270px;"  data-options="label:'领料人:',required:false"  />
			  	<input class="easyui-textbox" name="pickingPhone"  style="width:270px;"  data-options="label:'领料人电话:',required:false"  />
			 	<input class="easyui-textbox" name="sender"  style="width:270px;"  data-options="label:'发货人:'"  />
			 </div>
			 
			  <div style="margin-bottom:20px">
			  		<input class="easyui-datebox" name="outDate"   style="width:270px;"  data-options="label:'出库日期:',required:false"  />
			  </div>
			 
			 <div  style="margin-bottom:20px">
			 	<input class="easyui-textbox" name="remark" multiline="true" style="width:815px;height:60px;"  data-options="label:'备注:',required:false,validType:'length[0,500]'"  />
			 </div>
			 
			 <div style="margin-bottom:20px">
			 	<input class="easyui-layuiupload" name="attachment" style="width:815px;" data-options="label:'附件:',upload:{auto:false,height:120}" />
			 </div>
			 
			 <div style="margin-bottom:20px;margin-left: 80px;">
				<table id="dataGrid" title="出库物料明细"  style="height:300px;width:730px;"></table>
			</div>
		</form>
	</div>
</body>
</html>